import { Controller, Param, Get, Post, Body, Query } from '@nestjs/common';
import { UserService } from './user.service';
import { Public } from '../../../../../common/public.decorator';
import { registeredUsersDto, getAllUserBodyDto } from './user.create.dto';

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  /**
   * 查询用户根据id
   * @param id
   */
  @Public()
  @Get('findUserById/:id')
  async findUserById(@Param('id') id: string) {
    const userRes = await this.userService.findUserById(id);
    return {
      code: 200,
      data: userRes,
      message: 'success',
    };
  }

  /**
   * 注册用户
   * @param registeredUsers
   */
  @Public()
  @Post('registeredUsers')
  async registeredUsers(@Body() registeredUsers: registeredUsersDto) {
    return await this.userService.registeredUsers(registeredUsers);
  }

  /**
   * 修改用户状态
   * @param id
   * @param query
   */
  @Get('changeStatus/:id')
  async changeStatus(@Param('id') id: string, @Query() query: any) {
    return await this.userService.changeStatus(id, query.state);
  }

  @Post('getAllUsers')
  async getAllUsers(
    @Body()
    body: getAllUserBodyDto,
  ) {
    return await this.userService.getAllUsers(body);
  }
}
